#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read(){
	int f=0,x=0;
	char ch=getchar();
	while(!isdigit(ch)){f|=(ch=='-');ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
int n,k,a[N],Q,ans;
signed main(){
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout);
	n=read(),k=read();
	for(int i=1;i<=n;i++) a[i]=read();
	Q=read();
	a[0]=a[n+1]=1e9;
	while(Q--){
		ans=0;
		int x=read(),l=read(),r=read();
		swap(a[x],a[x+1]);
		for(int i=l;i<=r;i++){
			int ls=i,rs=i,res=0,v=a[i];
			while(ls!=1||rs!=n){
				if(a[ls-1]<=v&&ls>1) ls--,res++;
				else if(a[rs+1]<=v&&rs<n) rs++,res++;
				else{
					v=min(a[ls-1],a[rs+1]);
					res+=k;
				}
			}
			ans=ans+res;
		}
		printf("%lld\n",ans);
	}
	return 0;
}
/*
7 7
4 3 2 1 2 3 4
5
1 1 3
2 3 5
3 2 5
4 1 5
5 1 5
*/
